# Copyright (c) 2025 Li Auto Inc. and its affiliates
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#
# plat.mk
#
# This global configure makefile for Mingw platform (Windows)
#

CROSS_COMPILE_LST:=/usr/lib/mingw64-toolchain/bin/x86_64-w64-mingw32-gcc	\
                   /usr/bin/x86_64-w64-mingw32-gcc

CROSS_COMPILE:=$(patsubst %gcc,%,$(firstword $(wildcard $(CROSS_COMPILE_LST))))

CC:=$(CROSS_COMPILE)gcc
AR:=$(CROSS_COMPILE)ar
LD:=$(CROSS_COMPILE)ld


# $1: LOCAL_TARGET, that is $(LOCAL_OUT)/$(LOCAL_MODULE).
# $2: $(LOCAL_OUT)/$(LOCAL_MODULE).robot.
define install-executable
@echo Install	$(BINDIR)/$(notdir $1).exe
$(hide)mkdir -p        $(BINDIR)
$(hide)cp -a $1.exe    $(BINDIR)
endef

GLOBAL_CFLAGS:= -DTARGET_PRODUCT_$(TARGET_PRODUCT_UPPER)	\
                -DPRODUCT=$(TARGET_PRODUCT_UPPER)

GLOBAL_CFLAGS+= -Wimplicit-function-declaration			\
                -Werror -Wall -Wextra -fno-ident

GLOBAL_LFLAGS:= -lm -lpthread -levent -liphlpapi -lws2_32 -static

ifeq ($(COVERAGE),1)
GLOBAL_CFLAGS+= --coverage
GLOBAL_LFLAGS+= --coverage
endif

ifeq ($(DEBUG), 1)
GLOBAL_CFLAGS += -ggdb3 -Og
else
GLOBAL_CFLAGS += -O2
endif

# vim:ft=make
#
